package com.sicheng.lc.lc笔试;

import java.util.Arrays;
import java.util.Scanner;

public class 拼接N个数得到最大值 {

    // 输入 n个数 拼接成的最大数 所有数不含前导0
    //  6
    //  9 98 76 55 65 123
    //  输出: 998766555123
    public static void main(String[] args) {
        // write your code here
        //6
        //9 998 9 96 87 65 123
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] a = new String[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.next();
        }
        Arrays.sort(a, (x, y) -> {
            if (y.length() > x.length() && y.startsWith(x))
                return -1;
            if (x.length() > y.length() && x.startsWith(y))
                return 1;
            return y.compareTo(x);
        });
        StringBuilder res = new StringBuilder(n << 4);
        for (String s : a) {
            res.append(s);
        }
        System.out.println(res);
    }
}
